﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TSVNAddinUtils
{
	public class UtilsCommandProvider
	{
		public UtilsCommandProvider()
		{
		}

		public virtual IUtilsCommand GetCommand(string[] args)
		{
			string keyCommand;
			if (args.Length == 0)
				keyCommand = "/help";
			else
				keyCommand = args[0].ToLower();

			Dictionary<string, IUtilsCommandFactory> commandFactories = GetCommandFactories();

			IUtilsCommand command;
			if (commandFactories.ContainsKey(keyCommand))
				command = commandFactories[keyCommand].CreateCommand();
			else
				command = commandFactories["/help"].CreateCommand();

			return command;
		}

		private Dictionary<string, IUtilsCommandFactory> GetCommandFactories()
		{
			var factories = new Dictionary<string, IUtilsCommandFactory>();
			factories.Add("/register", new RegisterCommandFactory());
			factories.Add("/unregister", new UnRegisterCommandFactory());
			factories.Add("/help", new HelpCommandFactory());

			return factories;
		}
	}
}
